package com.va1m.demo.controller;

import com.va1m.demo.common.Result;
import com.va1m.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;

/**
 * 用户信息的controller
 * @author Admin
 */
@Controller
@RequestMapping("/api/user")
public class UserController {
    @Autowired
    UserService userService;

    /**
     * 前往用户信息页面
     * @return
     */
    @GetMapping("/index")
    public String returnUserIndex(){
        return "account";
    }

    /**
     * 查询用户信息
     * @param userId
     * @return
     */
    @ResponseBody
    @GetMapping("/getUserInfo")
    public Result getUserInfo(@RequestParam(value = "userId") Integer userId){
        return Result.ok(userService.getUserInfo(userId));
    }

    @ResponseBody
    @GetMapping("/addMoney")
    public Result addMoney(@RequestParam(value = "money")BigDecimal money,
                           @RequestParam(value = "userId") Integer userId){
        return Result.ok(userService.addMoney(userId,money));
    }
}
